#ifndef SETTINGMANAGE_H
#define SETTINGMANAGE_H

#include <QObject>
#include <QSettings>
#include <QVariant>
#include <QSet>
#include <QDebug>
#include <QTextCodec>
#include <QRegularExpression>

class SettingManage:public QObject
{
public:
    explicit SettingManage(QObject *parent = nullptr);
    ~SettingManage();
    static SettingManage* instance();// 单例模式访问
    void setValue(const QString &key, const QVariant &value);
    QVariant getValue(const QString &key, const QVariant &defaultValue = QVariant()) const;
    // 检查配置是否存在
    bool contains(const QString &key) const;
    // 删除配置项
    void remove(const QString &key);
    // 同步到磁盘
    void sync();
    //批量读取
    QVector<QString> readBatchKeys(const QString &section, const QString &baseKey) ;
    //批量写入
    void writeBatchKeys(const QString &section, const QString &baseKey, const QVector<QString> &values);
    //筛选出所有键
    QStringList getDistinctPrefixes(const QString &section, const QString &delimiter = "_");
    //添加单个配置文件分组项
    void addSingleConfigData(const QString &section, const QString &prefix, const QString &value);
    //修改配置文件分组项
    int updateConfigValuesByPrefix(const QString &section, const QString &prefix, const QString &oldValue,
                                  const QString &newValue);
    //删除配置文件分组项
    int deleteConfigValuesByPrefix(const QString &section, const QString &prefix, const QString &Value);
private:
    static SettingManage* m_instance;
    QSettings *m_pSettings;

};

#endif // SETTINGMANAGE_H
